const app = getApp();
const publicFun = require('/utils/public.js');
import { getAuthCode } from '/utils/request'
Page({
  data: {
    threeHours: 0,
  },
  onLoad() {},
  onShow() {
    my.setNavigationBarColor({
      frontColor: '#000000',
      backgroundColor: '#ffffff',
    })

    this.setData({
      systemInfo: app.globalData.systemInfo,
      userData: {},
      userid: ""
    })

    if (typeof this.getTabBar === "function" && this.getTabBar()) {
      this.getTabBar().setData({
        selected: 2 // 这里是tabbar下标，每个tabbar页面都需要写一下。
      });
    }
    if(app.globalData.userid){
      this.setData({
        userid: app.globalData.userid,
        userData: app.globalData.userData,
      })
    }
  },

  modifyUserData() {
    if(app.globalData.userid){
      let data = this.data.userData;
      my.navigateTo({
        url: '/pages/myUserData/myUserData?Url='+data.Url+'&UserName='+data.UserName+'&Phone='+data.Phone
      });
    }else{
      publicFun.jumpLogin();
    }
  },
  myClimateList() {
    if(app.globalData.userid){
      let data = this.data.userData;
      my.navigateTo({
        url: '/pages/myClimateList/myClimateList'
      });
    }else{
      publicFun.jumpLogin();
    }
  },
  myCheckInList() {
    if(app.globalData.userid){
      let data = this.data.userData;
      my.navigateTo({
        url: '/pages/userCheckInList/userCheckInList'
      });
    }else{
      publicFun.jumpLogin();
    }
  },
  myByoList() {
    if(app.globalData.userid){
      my.navigateTo({
        url: '/pages/myByoList/myByoList'
      });
    }else{
      publicFun.jumpLogin();
    }
  },
  myReward() {
    if(app.globalData.userid){
      my.navigateTo({
        url: '/pages/myReward/myReward'
      });
    }else{
      publicFun.jumpLogin();
    }
  },
  myOrgan() {
    if(app.globalData.userid){
      if(this.data.userData.ngoid > 0){
        my.navigateTo({
          url: '/pages/myOrganDetail/myOrganDetail?ngoId='+this.data.userData.ngoid
        })
      }else{
        my.navigateTo({
          url: '/pages/myOrgan/myOrgan'
        })
      }
    }else{
      publicFun.jumpLogin();
    }
  },
  myFeedback() {
    if(app.globalData.userid){
      my.navigateTo({
        url: '/pages/myFeedback/myFeedback'
      })
    }else{
      publicFun.jumpLogin();
    }
  },

  signOut() {
    my.clearStorage();
    publicFun.showToast("退出成功", 2000);
    // my.removeStorage({key: 'userid'});
    // my.removeStorage({key: 'usermiyao'});
    // my.removeStorage({key: 'userData'});
    // my.removeStorage({key: 'zfbUid'});
    app.globalData.userid = '';
    app.globalData.usermiyao = '';
    app.globalData.userData = null;
    setTimeout(() => {
      my.switchTab({
        url: '/pages/index/index',
      });
    }, 500)
  },

  onPullDownRefresh() {
    // 页面被下拉
    my.startPullDownRefresh();
    this.setData({
      userData: app.globalData.userData
    })
    my.stopPullDownRefresh();
  },
});
